﻿Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args) {
    if (args.get_error() != undefined && args.get_error().httpStatusCode == '500') {
        var markup = '<div id="dialogOverlay"></div>';
        $(markup).hide().appendTo('body').show();

        var dialogContent = '<div id="dialogBox"><h1>Error</h1><p style="text-align:left;">' + args.get_error().message + '</p><div id="dialogButtons"><input id="OKInfoDialog" type="button" class="button" value="OK" /><div style="clear:both;"></div></div></div>';
        $(dialogContent).hide().appendTo('body').show();

        args.set_errorHandled(true);

        var winH = $(window).height();
        var winW = $(window).width();

        $('#dialogBox').css('top', (winH / 2 - $('#dialogBox').height() / 2) - 50);
        $('#dialogBox').css('left', winW / 2 - $('#dialogBox').width() / 2);

        $('#OKInfoDialog').click(function () {
            $('#dialogBox').remove();
            $('#dialogOverlay').remove();
        });
    }

}